package com.haian.slidealbum.model.delegate;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.Handler;
import android.util.Log;

import com.haian.slidealbum.common.serviceforjson.utils.HttpConnectionUtils;

public class ServiceDelegate {

	//for facebook
	public static final String LINK_FACEBOOK = "https://graph.facebook.com/";
	public static final String LINK_FACEBOOK_ALBUM = "https://graph.facebook.com/me/albums";//https://graph.facebook.com/me/albums?access_token=
	public static String LINK_FACEBOOK_IMAGE = "/photos";//https://graph.facebook.com/223643860987514/photos?access_token=
	
	public static final String KEY_ACCESS_TOKEN = "access_token";
	public static final String KEY_DATA = "data";
	public static final String KEY_ID = "id";
	public static final String KEY_COUNT = "count";
	public static final String KEY_NAME = "name";
	public static final String KEY_IMAGE = "images";
	public static final String KEY_HEIGHT = "height";
	public static final String KEY_WIDTH = "width";
	public static final String KEY_SOURCE = "source";
	
	public static Thread getFacebookAlbum(final Handler handler, String access_token) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(KEY_ACCESS_TOKEN, access_token));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				HttpConnectionUtils.getFromURL(LINK_FACEBOOK_ALBUM, params, handler, null);
			}
		};
		return HttpConnectionUtils.performOnBackgroundThread(runnable);
	}
	
	public static Thread getFacebookImage(final Handler handler, String access_token, final String id_album) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(KEY_ACCESS_TOKEN, access_token));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				LINK_FACEBOOK_IMAGE = LINK_FACEBOOK + id_album + LINK_FACEBOOK_IMAGE;
//				Log.d("Luong", "Luong______________________ LINK_FACEBOOK_IMAGE: "+LINK_FACEBOOK_IMAGE);
				HttpConnectionUtils.getFromURL(LINK_FACEBOOK_IMAGE, params, handler, null);
			}
		};
		return HttpConnectionUtils.performOnBackgroundThread(runnable);
	}
	
	
	
	//for Instagram
	public static final String LINK_INSTAGRAM = "https://api.instagram.com/v1/users/self/media/recent";
	public static final String KEY_LOW_RESOLUTION = "low_resolution";
	public static final String KEY_THUMBNAIL = "thumbnail";
	public static final String KEY_STAND_RESOLUTION = "standard_resolution";
	public static final String KEY_URL = "url";
	
	public static Thread getInstagramImage(final Handler handler, String access_token) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(KEY_ACCESS_TOKEN, access_token));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				HttpConnectionUtils.getFromURL(LINK_INSTAGRAM, params, handler, null);
			}
		};
		return HttpConnectionUtils.performOnBackgroundThread(runnable);
	}
	
	//for Flick
		public static final String LINK_FLICKR = "https://www.flickr.com/services/rest/";
		public static final String KEY_PHOTOSETS = "photosets";
		public static final String KEY_TOTAL = "total";
		public static final String KEY_PHONESET = "photoset";
		public static final String KEY_API = "api_key";
		public static final String KEY_FORMAT = "format";
		public static final String KEY_PHONESET_ID = "photoset_id";
		public static final String KEY_USER_ID = "user_id";
		public static final String KEY_METHOD= "method";
		public static final String KEY_STAT= "stat";
		public static final String KEY_TOTAL_PHOTOS= "photos";
		public static final String KEY_TITLE= "title";
		public static final String KEY_CONTENT= "_content"; 
		public static final String KEY_PHOTO= "photo";
		public static final String KEY_SECRET= "secret";
		public static final String KEY_SERVER= "server";
		public static final String KEY_FARM= "farm";
		
		
		
		
		
		
		
		
		
		
		
		public static Thread getFlickrAlbum(final Handler handler, String user_id) {
			final List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair(KEY_METHOD, "flickr.photosets.getList"));
			params.add(new BasicNameValuePair(KEY_API, "3fbdcae9fb5516787682c426401f1ebb"));
			params.add(new BasicNameValuePair(KEY_FORMAT, "json"));
			params.add(new BasicNameValuePair(KEY_USER_ID, user_id));
			final Runnable runnable = new Runnable() {
				@Override
				public void run() {
					Log.d("Luong", "Luong______________________- LINK_FLICKR: "+LINK_FLICKR);
					HttpConnectionUtils.getFromURLForJsonFlickr(LINK_FLICKR, params, handler, null);
				}
			};
			return HttpConnectionUtils.performOnBackgroundThread(runnable);
		}
		
		public static Thread getFlickrImage(final Handler handler, String photoset_id) {
			final String urlFlicrImage = LINK_FLICKR;
			final List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair(KEY_METHOD, "flickr.photosets.getPhotos"));
			params.add(new BasicNameValuePair(KEY_API, "3fbdcae9fb5516787682c426401f1ebb"));
			params.add(new BasicNameValuePair(KEY_FORMAT, "json"));
			params.add(new BasicNameValuePair(KEY_PHONESET_ID, photoset_id));
			final Runnable runnable = new Runnable() {
				@Override
				public void run() {
					HttpConnectionUtils.getFromURLForJsonFlickr(urlFlicrImage, params, handler, null);
				}
			};
			return HttpConnectionUtils.performOnBackgroundThread(runnable);
		}
	
}
